package com.atguigu.spzx.user.controller;

import com.atguigu.spzx.model.entity.user.UserAddress;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.user.service.UserAddressService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "会员地址模块")
@RestController
@RequestMapping("/api/user/userAddress")
public class UserAddressController {
    ///api/user/userAddress/auth/findUserAddressList
    @Resource
    UserAddressService userAddressService;
    @Operation(summary = "查询指定id的地址信息")
    @GetMapping("/auth/findUserAddressById/{id}")
    public Result findUserAddressById(@PathVariable("id")Long id){
        UserAddress userAddress = userAddressService.findUserAddressById(id);
        return Result.ok(userAddress);
    }
    @Operation(summary = "新增地址")
    @PostMapping("/auth/save")
    public Result save(@RequestBody UserAddress userAddress){
        userAddressService.save(userAddress);
        // 如果前端需要局部刷新 可以返回增删改的对象
        return Result.ok(userAddress);
    }
    @Operation(summary = "查询会员的地址列表")
    @GetMapping("/auth/findUserAddressList")
    public Result findUserAddressList(){
        List userAddressList = userAddressService.findUserAddressList();
        return Result.ok(userAddressList);
    }
}
